package com.yxym.homework06;
/*
类SavingAccount每个月都有利息产生(earnMonthlyInterest方法调用)
并且每月有三次手续费的存款或取款，earnMonthlyInterest方法中重置交易计数
 */
public class SavingsAccount extends BankAccount{
    private int count;
    private double rate = 0.01;//利率

    public SavingsAccount(int initialBalance, int count, double rate) {
        super(initialBalance);
        this.count = count;
        this.rate = rate;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    @Override
    public void deposit(double amount) {
        //判断是否可以免手续费
        if(count > 0 ){
            super.deposit(amount);
        }else{
            super.deposit(amount - 1 );//减去1元
        }
        count --;
    }

    @Override
    public void withdraw(double amount) {
        //判断是否可以免手续费
        if(count > 0 ){
            super.withdraw(amount);
        }else{
            super.withdraw(amount + 1 );//转入1元
        }
        count --;
    }
    public void earnMonthlyInterest(){
        count = 3 ;//每月初统计上个月底月息，count = 3
        super.deposit(getBalance() * rate);
    }
}
